package unit9;

//创建存储过程p1
// DELIMITER $$
// CREATE PROCEDURE p1(IN name VARCHAR(10),OUT con INT)
// BEGIN
// INSERT INTO STUDENT_INF (id,name,gender,age) VALUES (6,name,’女’，17）；
// SELECT count(1) INTO con FROM STUDENT_INF;
// SELECT * FROM STUDENT_INF;
// END $$
// DELIMITER ;
//Java源程序代码
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;
public class Ex9_4_Example9_4 {
    public static void main(String[] args) throws Exception{
        Connection con = new Ex9_2_Example9_2().getConnection(); //创建连接
        CallableStatement cs = con.prepareCall("CALL p1(?,?);");
        cs.setString(1, "乐乐");
        cs.registerOutParameter(2, Types.INTEGER);
        cs.execute();
        ResultSet set = cs.getResultSet(); //获取输出结果
        while (set.next()) {
            System.out.print(set.getString("NAME") + " ");
        }
        //获取输出参数的结果
        int i = cs.getInt(2);
        System.out.print("i:" + i);
    }
}
